#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
typedef unsigned char uchar;

void dump_flash(void *data, int len)
{
    int i = 0;
    for(i=0; i < len ;i++)
    {
        if(i > 0 && i %16 == 0)
        {
            printf("\n");
        }
        printf("%02X ", *((unsigned char *)data+i));
    }
    printf("\n");
}

void dump_array(char (*data)[16], int len)
{
    int i = 0, j = 0;


    for(i = 0; i< len; i++)
    {
        for(j = 0; j < len;j++)
        {
            //printf("%d ",arr16_16[i][j]);
            if(data[j][i])
            {
                printf("##");
            }else{
                printf("  ");
            }
        }
        printf("\n");
    }
}

void dump_oled(uchar (*data)[2], int len)
{
    int i = 0, j = 0;
    for(i = 0; i < len; i++)
    {
        for(j = 0;j < 32;j++)
        {
            printf("%02X ", data[j][i]);
        }
        printf("\n");
    }
}

void delay_ms(int ms)
{
    usleep(ms * 1000);
}

uint32_t get_random(uint32_t random_seed, uint32_t min, uint32_t max)
{
    uint32_t value;
    
    srand(random_seed);
    value =  rand() % (max + 1 - min)+ min;
 
    return value;
}

uint8_t random_event(uint32_t cnt, uint8_t yes_present, uint8_t up)
{
    
    uint8_t rander = 0;;
    rander = get_random(cnt,0, up);
    if(rander < yes_present)
    {
        return 1;
    }
    return 0;
}
